package pro.lingwu.station.service.impl;

import org.springframework.stereotype.Service;
import pro.lingwu.station.dao.PassengerMapper;
import pro.lingwu.station.dto.db.Passenger;
import pro.lingwu.station.service.PassengerService;

import java.util.List;

/**
 * @author @lingwu
 * @date created in 12/26/2021
 */
@Service
public class PassengerServiceImpl implements PassengerService {
    private final PassengerMapper mapper;

    public PassengerServiceImpl(PassengerMapper mapper) {
        this.mapper = mapper;
    }

    @Override
    public void addPassenger(Passenger passenger) {
        for (var item : mapper.findPassengerByAccount(passenger.getAccount())) {
            if (item.getName().equals(passenger.getName())) return;
        }
        mapper.addPassenger(passenger);
    }

    @Override
    public List<Passenger> findPassengerByAccount(String account) {
        return mapper.findPassengerByAccount(account);
    }

    @Override
    public void rmPassenger(Long id) {
        mapper.rmPassenger(id);
    }
}
